package com.zretc.api;
/**
短信验证码
 商品购买地址： https://market.aliyun.com/products/57126001/cmapi024822.html
 String host = "https://fesms.market.alicloudapi.com"; //服务器
 String path = "/sms/"; //接口地址
 */

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.zretc.util.HttpUtils;

import java.util.HashMap;
import java.util.Map;

public class SendCaptcha {
/*    public static void main(String[] args) {
        String host = "https://fesms.market.alicloudapi.com";
        String path = "/sms/";
        String method = "GET";
        String appcode = "96329c14ab344c77b88ecfc88bf4313c";  // !!! 替换这里填写你自己的AppCode 请在买家中心查看
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode); //格式为:Authorization:APPCODE 83359fd73fe11248385f570e3c139xxx
        Map<String, String> querys = new HashMap<String, String>();
        Integer random = (int)(Math.random()*900000)+10000;
        querys.put("code", random.toString());// !!! 请求参数
        querys.put("phone", "18030253722");// !!! 请求参数
        querys.put("skin", "1");// !!! 请求参数
        try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString()); //输出头部
            System.out.println(EntityUtils.toString(response.getEntity())); //输出json
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/
    
    public String getCaptcha(String phoneNum) {
        String host = "https://fesms.market.alicloudapi.com";
        String path = "/sms/";
        String method = "GET";
        String appcode = "96329c14ab344c77b88ecfc88bf4313c";  // !!! 替换这里填写你自己的AppCode 请在买家中心查看
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode); //格式为:Authorization:APPCODE 83359fd73fe11248385f570e3c139xxx
        Map<String, String> querys = new HashMap<String, String>();
        Integer random = (int)(Math.random()*900000)+10000;
        querys.put("code", random.toString());// !!! 请求参数
        querys.put("phone", phoneNum);// !!! 请求参数
        querys.put("skin", "1");// !!! 请求参数
        try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString()); //输出头部
            System.out.println(EntityUtils.toString(response.getEntity())); //输出json
        } catch (Exception e) {
            e.printStackTrace();
        }
        return random.toString();
	}
}
